name: pre-commit

on:
  pull_request:
  push:

jobs:
  pre-commit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: "3.11"
          cache: "pip"
      - uses: pre-commit/action@v3.0.0

  pytest:
    if: github.ref == 'refs/heads/main' || github.event_name == 'pull_request'
    name: PyTest
    needs: [pre-commit]
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python_version: ["3.9", "3.10", "3.11"]
    timeout-minutes: 5

    steps:
      - uses: actions/checkout@v3
      - name: Setup Python
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python_version }}
          cache: "pip"
      - name: Install dependencies
        run: pip3 install -U -e .[test]
      - name: Run tests
        run: pytest .
